'use strict';

const {
	platform
} = require("process");

module.exports = {
	/**
	 * XXXnameXXX
	 * @url client/user/kh/dingyue 前端调用的url参数地址
	 * data 请求参数
	 * @param {String} params1  参数1
	 */
	main: async (event) => {
		const db = uniCloud.database();

		let {
			data = {}, userInfo, util, filterResponse, originalParam
		} = event;
		let {
			customUtil,
			uniID,
			config,
			pubFun,
			vk,
			_
		} = util;
		let {
			uid,
			tv_id,
			tv_name,
			msgType,
			msglist
		} = data;
		let res = {
			code: 0,
			msg: ""
		};
		// 业务逻辑开始-----------------------------------------------------------
		var platform = data.platform || "weixin";
		var nowtime = new Date().getTime();
		console.log("platform=", platform);
		if (platform == "weixin") {
			const add1 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.wx_openid['mp-weixin'],
				msgType: "xspsx",
				muban_id: msglist[0] || "",
				is_send: false,
				platform: "weixin",
				appid: userInfo.appid,
				appname: userInfo.appname,
				_add_time: nowtime
			})
			const add3 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.wx_openid['mp-weixin'],
				msgType: "flhd",
				muban_id: msglist[1] || "",
				is_send: false,
				platform: "weixin",
				appid: userInfo.appid,
				appname: userInfo.appname,
				_add_time: nowtime
			})
			const add2 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.wx_openid['mp-weixin'],
				tv_id: tv_id,
				tv_name: tv_name,
				msgType: "jjgx",
				muban_id: msglist[2] || "",
				is_send: false,
				platform: "weixin",
				appid: userInfo.appid,
				appname: userInfo.appname,
				_add_time: nowtime
			})




		}

		if (platform == "toutiao") {


			const add5 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.tt_openid,
				msgType: "rbxj", //热播新剧
				muban_id: msglist[0] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "toutiao",
				_add_time: nowtime
			})
			const add4 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.tt_openid,
				msgType: "qdtx", //签到提醒
				muban_id: msglist[1] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "toutiao",
				_add_time: nowtime
			})
			const add6 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.tt_openid,
				tv_id: tv_id || "no",
				tv_name: tv_name || "no",
				msgType: "jjgx", //剧集更新
				muban_id: msglist[2] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "toutiao",
				_add_time: nowtime
			})
		}

		if (platform == "kuaishou") {
			const add7 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.ks_openid,
				tv_id: tv_id,
				tv_name: tv_name,
				msgType: "zjgx", //追剧更新
				muban_id: msglist[0] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "kuaishou",
				_add_time: nowtime
			})

			const add8 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.ks_openid,
				msgType: "rbxj", //热播新剧
				muban_id: msglist[1] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "kuaishou",
				_add_time: nowtime
			})

			const add9 = await db.collection('a_dingyue').add({
				user_id: userInfo._id,
				openid: userInfo.ks_openid,
				msgType: "qdtx", //签到提醒
				muban_id: msglist[2] || "",
				is_send: false,
				appid: userInfo.appid,
				appname: userInfo.appname,
				platform: "kuaishou",
				_add_time: nowtime
			})
		}

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}